from functools import partial
import sys


class Templet(object):

    '''在 Python 中，以双下划线开头，并且以双下划线结尾（即 __xxx__）的变量是特殊变量，特殊变量是可以直接访问的。所以，不要用 __name__ 这样的变量名。

    另外，如果变量名前面只有一个下划线 _，表示不要随意访问这个变量，虽然它可以直接被访问。 '''

    fibonacci = []

    def __new__(cls, *args, **kwargs):
        '''__new__ called when a object created'''
        print("__new__ --> ")
        # 可以尝试去掉下面的return语句观察会有什么结果
        return object.__new__(cls)

    def __init__(self, name, age=18, estate=0,*args):
        # '''__init__ called when a object created to initialize object'''
        print("__init__ --> ")
        self.name = name
        self._age = age
        self.__estate = estate
        for item in args:
            if isinstance(item,int):
                print()


    __slots__ = ('name', '_age', '__estate')


    def __call__(self, *args, **kwargs):
        '''__call__ called when a object created'''
        print("__call__ --> ")

    def __str__(self):
        ''' print object to string'''
        return str(self.name) + "\t" + str(self._age) + "\t" + str(self.__estate)

    # __repr__ = __str__
    def __repr__(self):
        '''print to string when use object directly'''
        return "object Templet " + str(self.name) + "\t" + str(self._age) + "\t" + str(self.__estate)

    def __enter__(self):
        '''context manager: do something before function'''
        print("I'm context manager: Doing __enter__")

    def __exit__(self, exc_type, exc_val, exc_tb):
        '''context manager: do something after function'''
        print("I'm context manager: Doing __exit__")

    # def __next__(self):

    # @classmethod
    # def func(cls):
    #     print("class method function")


if __name__ == '__main__':
    templet = Templet("XX")
    templet             #__repr__
    print(templet)      #__str__
    print(Templet.__str__.__doc__)

